<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px; " >
    <form class="layui-form" >
        <div class="layui-form-item"  >
            <h2 style = "text-indent:6em"> 
                修改用户【
                <font color="#104E8B" id = "uctrname" ></font>
                】的金币
            </h2>
        </div>
         <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px;">游戏推广号：</label>
            <div class="layui-form-mid">
                <font color="#104E8B" id = "uctrlGameID"></font>
            </div>    
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label" style="width:100px;">当前金币：</label>
            <div class="layui-form-mid">
                <font color="#FF0000" id = "uCtrlOldGold"></font>
            </div>    
        </div>
     

        <div class="layui-form-item" >
            <label class="layui-form-label"  style="width:100px;">添加金币：</label>
            <div class="layui-input-inline">
                   <input class="layui-input" type="number" name="uCtrlAddGold" id="uCtrlAddGold" oninput="OnInput(event)"  onpropertychange="OnPropChanged (event)" autocomplete="off"  lay-verify="required"  value="0"  >
            </div> 
             <div class="layui-form-mid">
                <font color="#104E8B" id = "UserGoldChina"></font>
            </div> 
        
        </div>

        <div class="layui-form-item" style = "text-indent:10em" >
             <div class="layui-form-mid">
                <font color="#FF0000" >
                    *减少金币为负数，添加金币为正数
                </font>
            </div> 
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label"  style="width:100px;">修改理由：</label>
            <div class="layui-input-block">
                    <textarea style="height:100px;width:400px" name="ctrlreson" id="ctrlreson" placeholder="请输入内容" lay-verify="required" class="layui-textarea" maxlength="127"></textarea>
            </div>     
        </div>

        <div class="layui-form-item" >
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="useroprater">确定修改</button>
            </div>
        </div>

    </form>
</div>
<script>
var $;
    layui.config({
            base : "js/"
    }).use(['form','element','layer','jquery'],function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;

        ShowContlrDatas();
        form.on('submit(useroprater)', function(data){
            var ctrlreson = document.getElementById("ctrlreson");
            var uCtrlAddGold = document.getElementById("uCtrlAddGold");
            var uCtrlUserGold = (localStorage['uCtrlGold'] *-1);
            if (uCtrlAddGold.value < uCtrlUserGold  )
            {
                uCtrlAddGold.value=uCtrlUserGold;
            }
          
            if (uCtrlAddGold.value != 0 )
            {
                var form_data = {
                    'uCtrlType': [|.uCtrlType|]
                    ,'uCtrlUserID': localStorage["gameid"]
                    ,'uCtrlName': localStorage["unickname"]
                    ,'uCtrlAddGold': uCtrlAddGold.value
                    ,'uCtrlGold': localStorage['uCtrlGold']
                    ,'uCtrlReaSonStr':ctrlreson.value
                }
                layer.confirm('你确定修改：【'+ localStorage["unickname"]+'】的金币么吗？', function(index){
                    $.post('[|urlfor "UsersFinduserController.UserContrlInfo"|]', form_data, function (out) {
                        if (out.status == 0) {
                            layer.msg(out.message.strOKMessage,{icon: 1},function () {
                                localStorage["uCtrlGold"] =out.message.GoldS;
                                window.location.reload()
                            })
                        } else {
                            layer.msg(out.message)
                        }
                    }, "json");
                });
                return false;
             }
          
        });
    return false;
}); 

// Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
function OnInput (event) {  
    var UserGoldChina = document.getElementById("UserGoldChina");
    var data = event.target.value;
    var lenth = 15
    if(data.length>lenth)
    {
      var uCtrlAddGold = document.getElementById("uCtrlAddGold");
      uCtrlAddGold.value=data.slice(0,lenth)
      return
    }
    UserGoldChina.innerHTML=numtransferchinese(data)
}
// Internet Explorer
function OnPropChanged (event) {
    var UserGoldChina = document.getElementById("UserGoldChina");
    var data = event.target.value;
    var lenth = 15
    if(data.length>lenth)
    {
      var uCtrlAddGold = document.getElementById("uCtrlAddGold");
      uCtrlAddGold.value=data.slice(0,lenth)
      return
    }
    UserGoldChina.innerHTML=numtransferchinese(data)
}
function ShowContlrDatas(){
    var uctrname =  document.getElementById("uctrname");
    uctrname.innerHTML=localStorage["unickname"];
    var uctrlGameID =  document.getElementById("uctrlGameID");
    uctrlGameID.innerHTML=localStorage["gameid"];
    var uCtrlOldGold = document.getElementById("uCtrlOldGold");
    uCtrlOldGold.innerHTML=localStorage["uCtrlGold"];
 
    
}

function numtransferchinese(data)
{
    if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(data)) 
    {
        return "";
    }
    var unit = "京亿万仟佰拾兆万仟佰拾亿仟佰拾万仟佰拾 ", 
    str = "";
    unit = unit.substr(unit.length - data.length); 
    for (var i=0; i < data.length; i++)
    { 
        str += '零壹贰叁肆伍陆柒捌玖'.charAt(data.charAt(i)) + unit.charAt(i);  
    }
    str = str.replace(/零(仟|佰|拾)/g, "零");
    str = str.replace(/(零)+/g, "零");
    str = str.replace(/零(兆|万|亿)/g, "$1");
    str = str.replace(/(兆|亿)万/g, "$1");
    str = str.replace(/(京|兆)亿/g, "$1");
    str = str.replace(/(京)兆/g, "$1");
    str = str.replace(/(京|兆|亿|仟|佰|拾)(万?)(.)仟/g, "$1$2零$3仟")
    str = str.replace(/(零)+/g, "零");
   if (str.length > 2)
   {
        var indexdata = str.length-2;
        
        if (str.charAt(indexdata) == "零")
        {
            str = str.substr(0,indexdata)
        }
   }
    return str;
}

</script>